<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录 - AI简历分析</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            max-width: 400px;
            width: 100%;
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="email"], input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
        }
        .btn {
            background: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        .btn:hover {
            background: #0056b3;
        }
        .error {
            color: red;
            margin: 10px 0;
            text-align: center;
            padding: 10px;
            background-color: #ffe6e6;
            border-radius: 5px;
            border: 1px solid #ffcccc;
        }
        .register-link {
            text-align: center;
            margin-top: 20px;
        }
        .register-link a {
            color: #007bff;
            text-decoration: none;
        }
        .register-link a:hover {
            text-decoration: underline;
        }
        .jwt-info {
            margin-top: 20px;
            padding: 10px;
            background-color: #f0f8ff;
            border-radius: 5px;
            border: 1px solid #cce5ff;
            font-size: 12px;
            color: #004085;
        }
        .logo {
            text-align: center;
            margin-bottom: 20px;
        }
        .logo img {
            height: 60px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="logo">

    </div>

    <h1>用户登录</h1>

    <form id="loginForm" th:action="@{/login}" method="post">
        <div class="form-group">
            <label for="email">邮箱</label>
            <input type="email" id="email" name="email" required>
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password" required>
        </div>

        <div class="form-group">
            <label>
                <input type="checkbox" id="rememberMe" name="rememberMe"> 记住我
            </label>
        </div>

        <div th:if="${error}" class="error" th:text="${error}"></div>

        <button type="submit" class="btn">登录</button>
    </form>

    <div class="register-link">
        还没有账号？<a th:href="@{/register}">立即注册</a>
    </div>

    <div class="jwt-info">
        <strong>安全提示：</strong>系统使用JWT令牌进行身份验证，登录后令牌将存储在安全的HttpOnly Cookie中。
    </div>
</div>

<script>
    // 页面加载时检查是否有已保存的邮箱
    document.addEventListener('DOMContentLoaded', function() {
        const savedEmail = localStorage.getItem('rememberedEmail');
        if (savedEmail) {
            document.getElementById('email').value = savedEmail;
            document.getElementById('rememberMe').checked = true;
        }

        // 表单提交事件
        document.getElementById('loginForm').addEventListener('submit', function() {
            if (document.getElementById('rememberMe').checked) {
                // 保存邮箱到本地存储
                localStorage.setItem('rememberedEmail', document.getElementById('email').value);
            } else {
                // 清除保存的邮箱
                localStorage.removeItem('rememberedEmail');
            }
        });

        // 检查URL参数，显示注册成功消息
        const urlParams = new URLSearchParams(window.location.search);
        if (urlParams.get('registered') === 'true') {
            const errorDiv = document.createElement('div');
            errorDiv.className = 'error';
            errorDiv.style.backgroundColor = '#e6ffe6';
            errorDiv.style.borderColor = '#ccffcc';
            errorDiv.style.color = '#155724';
            errorDiv.textContent = '注册成功，请登录';
            document.querySelector('.form-group:last-child').after(errorDiv);
        }
    });
</script>
</body>
</html>